const mongoose = require("mongoose");
const dbg = require("debug")("[mongo.js]");
dbg.enabled = true;
mongoose.connect(process.env['MONGO_URI']||"mongodb://localhost:27017/mht-foobar",{
    autoReconnect:true,
    connectTimeoutMS:30000000000000,
    socketTimeoutMS:30000000000000
});

mongoose.connection.on("open", () => {
    dbg("connected");
})

const MhtFileSchema = new mongoose.Schema({
    filename: String,
    boundary: String
});

const MhtFile = mongoose.model("mht_file", MhtFileSchema);




const HtmlMsgSchema = new mongoose.Schema({
    html: String,
    visited: Boolean,
    boundary: String 
});

const HtmlMsg = mongoose.model("html_message", HtmlMsgSchema);

const ImageSchema = new mongoose.Schema({
    cid: String,
    content: String,
    image_type:String,
    visited: Boolean,
    boundary: String
});

const Image = mongoose.model("image", ImageSchema);

module.exports = {
    MhtFile,
    Image,
    HtmlMsg
}